Step 1 - Use keyboard keys to navigate between Page nodes

In this step of the tutorial you create keyboard navigation between the Home, Media, Car, and Navigation application screens. You set focus to the toggle buttons on the navigation bar and set the application to navigate between the application screens when the user presses the (Right Arrow) and (Left Arrow) keyboard keys.

Assets for the tutorial

The starting point of this tutorial is the Keyboard input.kzproj Kanzi Studio project file stored in <KanziWorkspace>/Tutorials/Keyboard input/Start directory.

The <KanziWorkspace>/Tutorials/Keyboard input/Completed directory contains the completed project of this tutorial.

The starting point project contains the content you need to complete this tutorial:

Create keyboard navigation between application screens

In this section you create keyboard navigation for the toggle buttons you use to navigate between the Page nodes which show the application screens.

To create keyboard navigation between application screens:

  1. In the Project select the Screen node, in the Node Components > Triggers section right-click, and select Add Trigger > General > On Attached.
    When you start the application, Kanzi by default sets the focus to the Screen node. You use the On Attached trigger to set focus to the navigation bar when you start the application.
  2. In the Node Components add to the On Attached trigger a Set Focus action and in the Set Focus window set the Target Item to #NavigationButtons.
    You set focus to the Toggle Button Group 2D node NavigationButtons when the application starts to allow the user to move the focus in the focus chain. In the next step of this section you set the NavigationButtons node to forward the focus to the HomeButton node to create the navigation between the application screens.
  3. TIP

    You can define a focus chain using an alias or the path to each node.
    Aliases provide a convenient way to set the nodes in a focus chain. See Using aliases.

  4. In the Project > RootPage select the NavigationButtons node, in the Properties right-click, select Add Property > Focus Manager > Focus Scope property, and enable that property.
    You use the Focus Scope property to forward the focus from the NavigationButtons node to the HomeButton node to allow navigation between the application screens. This way the user can use keyboard keys to navigate between those toggle buttons.
  5. In the Project > RootPage > NavigationButtons > Grid Layout 2D select the HomeButton node, in the Properties right-click, select Add Property > Node > Logical Focus property, and enable that property.
    When you set focus to the focus scope node, the child node for which you enable the Logical Focus property receives focus. If the focus scope has several child nodes with the Logical Focus property enabled, the focus manager sets focus to the last child node.
    You set the HomeButton node to receive focus when you set focus to the Toggle Button Group 2D node NavigationButtons.
  6. In the Project > RootPage > NavigationButtons > Grid Layout 2D select the HomeButton node, in the Properties right-click, select Add Property > Focus Manager > Right Navigation Node, and set it to #MediaButton.
    The focus chain in Kanzi enables you to navigate between nodes based on their rendered position using the (Left Arrow), (Right Arrow), (Up Arrow), and (Down Arrow) keys. You use the Right Navigation Node property to set focus from the HomeButton node to the MediaButton node when the user presses the (Right Arrow) key on the keyboard.

  7. Repeat the previous step for the MediaButton and CarButton nodes but in the Properties set the Right Navigation Node property:
  8. In the Project > RootPage > NavigationButtons > Grid Layout 2D select the MediaButton node, in the Properties right-click, select Add Property > Focus Manager > Left Navigation Node property, and set it to #HomeButton.
    You use the Left Navigation Node property to set focus from the MediaButton node to the HomeButton node when the user presses the (Left Arrow) key on the keyboard.
  9. Repeat the previous step for the CarButton and NavigationButton nodes but in the Properties set the Left Navigation Node property:

Restart the Preview to set the initial focus to the HomeButton toggle button. You can now use the (Right Arrow) and (Left Arrow) keyboard keys to navigate between application screens.


< INTRODUCTION
NEXT STEP >

See also

To find out more about how focus works in Kanzi, see Focus.

To find out more about the Page and Page Host nodes, see Using the Page and Page Host nodes.

To find out more about using triggers, see Using triggers.